
using System;
using System.Linq;
using Csla;
using Csla.Data;

namespace HousingInfo.Library
{ 
	public partial class AreaBOList : Csla.BusinessListBase<AreaBOList, AreaBO>
	{

		#region Authorization Rules

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of AreaBOList
			//AuthorizationRules.AllowCreate(typeof(AreaBOList), "AreaBOListCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(AreaBOList), "AreaBOListEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(AreaBOList), "AreaBOListDeleteGroup"));
		}
		#endregion //Authorization Rules

        #region Phan trang su dung ojbectdatasource trang Areas
        //ham lay du lieu va phan trang
        public static AreaBOList GetAreaBOList_byPaging(int startRowIndex, int maximumRows)
        {
            return DataPortal.Fetch<AreaBOList>(new FilterAreas_byPaging(startRowIndex, maximumRows));
        }
        //tham so
        protected class FilterAreas_byPaging
        {
            public int StartRowIndex;
            public int MaximumRows;
            public FilterAreas_byPaging(int startRowIndex, int maximumRows)
            {
                this.StartRowIndex = startRowIndex;
                this.MaximumRows = maximumRows;
            }
        }
        //Truy cap du lieu va goi ham pham trang
        private void DataPortal_Fetch(FilterAreas_byPaging cretia)
        {
            bool cancel = false;
            OnFetching(ref cancel);
            if (cancel) return;

            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                RaiseListChangedEvents = false;

                this.AddRange(
                    from row in mgr.DataContext.AdminAreas_Page(cretia.StartRowIndex, cretia.MaximumRows)
                    select AreaBO.GetAreaBO(row.AreaID)
                );

                RaiseListChangedEvents = true;
            }//using
            //OnFetched();
        }
        #region Ham lay tong so tin
        public static int GetTotal_AdminAreas()
        {
            int count = 0;
            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                var result = mgr.DataContext.AdminAreas_Gettotal();
                count = result.First().Total.Value;
            }
            return count;
        }
        #endregion
        #endregion
    }
}
